﻿namespace ScrumFactory.Services.Web
{
    using System.ComponentModel.Composition.Extensions;
    using System.ComponentModel.Composition.Hosting;
    using System.Reflection;
    using System.ServiceModel.Activation;
    using System.Web.Routing;

    public class Application : System.Web.HttpApplication {

        public static CompositionContainer CompositionContainer { get; private set; }

        protected void Application_Start() {
            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new DirectoryCatalog(Server.MapPath("~/Bin"), "ScrumFactory.*.dll"));
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            catalog.Catalogs.Add(new ConfigurationCatalog());
            catalog.Catalogs.Add(new ConnectionStringCatalog());

            CompositionContainer = new CompositionContainer(catalog, true, null);


            RouteTable.Routes.Add(new ServiceRoute("ProjectsService", new MefWebServiceHostFactory(CompositionContainer), typeof(IProjectsService)));
            RouteTable.Routes.Add(new ServiceRoute("BacklogService", new MefWebServiceHostFactory(CompositionContainer), typeof(IBacklogService)));
            RouteTable.Routes.Add(new ServiceRoute("TeamService", new MefWebServiceHostFactory(CompositionContainer), typeof(ITeamService)));
            RouteTable.Routes.Add(new ServiceRoute("TasksService", new MefWebServiceHostFactory(CompositionContainer), typeof(ITasksService)));
            RouteTable.Routes.Add(new ServiceRoute("ProposalsService", new MefWebServiceHostFactory(CompositionContainer), typeof(IProposalsService)));
            RouteTable.Routes.Add(new ServiceRoute("AuthorizationService", new MefWebServiceHostFactory(CompositionContainer), typeof(IAuthorizationService)));

            RouteTable.Routes.Add(new ServiceRoute("WindowsAuthorizationService", new MefWebServiceHostFactory(CompositionContainer), typeof(IWindowsProviderService)));

            
        }
    }
}